#include "priorityqueue.h"

PriorityQueue::PriorityQueue()
{
}

void PriorityQueue::enqueue(DownloadTask *task){
    switch(task->priority()){
        case 0:
            lowQueue.enqueue(task);
            break;
        case 1:
            normalQueue.enqueue(task);
            break;
        case 2:
            highQueue.enqueue(task);
            break;
    }
}

bool PriorityQueue::isEmpty() const{
    return lowQueue.isEmpty() && normalQueue.isEmpty() && highQueue.isEmpty();
}

DownloadTask* PriorityQueue::dequeue(){
    if(!highQueue.isEmpty()){
        return highQueue.dequeue();
    }
    if(!normalQueue.isEmpty()){
        return normalQueue.dequeue();
    }

    return lowQueue.dequeue();
}
